//
//  DashesLineView.m
//  WideHelp
//
//  Created by ENERGY on 2018/8/12.
//  Copyright © 2018年 ENERGY. All rights reserved.
//

#import "DashesLineView.h"

@interface DashesLineView()
@property (nonatomic, assign)NSInteger lineLength;
@property (nonatomic, assign)NSInteger lineSpacing;
@property (nonatomic, strong)UIColor * lineColor;
@property (nonatomic, assign)CGFloat height;
@end

@implementation DashesLineView

//- (instancetype)initWithFrame:(CGRect)frame withLineLength:(NSInteger)lineLength withLineSpacing:(NSInteger)lineSpacing withLineColor:(UIColor *)lineColor{
//    self = [super initWithFrame:frame];
//    if (self) {
//        self.backgroundColor = [UIColor whiteColor];
//        _lineLength = lineLength;
//        _lineSpacing = lineSpacing;
//        _lineColor = lineColor;
//        _height = frame.size.height;
//    }return self;
//}
- (instancetype)init{
    self = [super init];
    if (self) {
        
    }return self;
}
- (void)setFrame:(CGRect)frame{
    [super setFrame:frame];
    _height = frame.size.height;
}
- (instancetype)initWithLineLength:(NSInteger)lineLength withLineSpacing:(NSInteger)lineSpacing withLineColor:(UIColor *)lineColor{
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        _lineLength = lineLength;
        _lineSpacing = lineSpacing;
        _lineColor = lineColor;
//        _height = frame.size.height;
    }return self;
}

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
    CGContextRef context =UIGraphicsGetCurrentContext();
    CGContextBeginPath(context);
    CGContextSetLineWidth(context,1);
    CGContextSetStrokeColorWithColor(context, _lineColor.CGColor);
    CGFloat lengths[] = {_lineLength,_lineSpacing};
    CGContextSetLineDash(context, 0, lengths,2);
    CGContextMoveToPoint(context, 0, 0);
    CGContextAddLineToPoint(context, 0,_height);
    CGContextStrokePath(context);
    CGContextClosePath(context);
}

@end
